// 上传 日记 接口
const db = require('../db')

exports.post = (req, res) => {
  // console.log(req)
  // console.log(req.body)
  const { id, content, tilength, cityname, wearther, nowicon, temperature, week, time, getdate } = req.body // 将传递进来的数据保存
  // console.log(id, content, tilength, cityname, wearther, nowicon, temperature, week, time, date)
  const insertArticleSql = `insert into article (id, content, tilength, cityname, wearther, nowicon, temperature, week, time, date) values ('${id}','${content}','${tilength}','${cityname}','${wearther}','${nowicon}','${temperature}','${week}','${time}','${getdate}')`
  db.query(insertArticleSql, (err, data) => {
    if (err) {
      // 数据库语句执行失败
      return console.log('insertArticleSql错误:' + err.sqlMessage)
    } else if (data.length < 1) {
      // 返回的值为空数组
      res.send({ data: null, mes: '添加日记失败', status: 401 })
    } else {
      res.send({ mes: '添加日记成功', status: 201 })
      // const { data } = data
      // console.log(data)
    }
  })
}
